# 给类增加属性的两种方式
# 对象的属性层层上找
# 修改 对象的 __class__ 属性，则只能找到新的指向类的属性。
# 如果对象本身有属性定义，则不会在类上面找。

class Money:
    age = 11
    num = 666
    pass


# Money.count = 1
# Money.age = 122

# print(Money.count)
print(Money.__dict__)

Money.age = 44
print(Money.age)

del Money.age # 只能删除自身的属性
# print(Money.age) # 报错
print('*'*10)

# {'__module__': '__main__', 'age': 11, 'num': 666, '__dict__': <attribute '__dict__' of 'Money' objects>, '__weakref__': <attribute '__weakref__' of 'Money' objects>, '__doc__': None}
# 44
# Traceback (most recent call last):
#   File "C:\Users\wyl350\Desktop\demo-python\ÃæÏò¶ÔÏó\class.py", line 22, in <module>
#     print(Money.age)
# AttributeError: type object 'Money' has no attribute 'age'

one = Money()
print(one)
print(one.__class__)
print(one.__dict__)

# print(one.age) # 这个属性删除了
print(one.num)

class Text:
    sex = 'male'

one.__class__ = Text

print(one.sex)
# print(one.age)
# print(one.num)

one.sex = 'femal'
print(one.sex)


